{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1171
  Verdict: Accepted
}
uses 
	SysUtils, Math;
 
var  	
	i,j,n,l,r,kk:longint;
	a,b:array[0..100010] of longint;
 
procedure siftdown(i:longint);
 
var 
  j,t:longint;
 
begin
while 2*i<=n do begin
  j:=i;
	if a[2*i]>a[j] then j:=2*i;
  if (2*i+1<=n) and (a[2*i+1]>a[j]) then j:=2*i+1;
	if i<j then begin
    t:=a[i];
    a[i]:=a[j];
    a[j]:=t;
    i:=j;
  end else break;
end;
end;
 
function ex_max:longint;
begin
result:=a[1];
a[1]:=a[n];
dec(n);
siftdown(1);
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
for i:=1 to n do 
	read(a[i]);
for i:=n downto 1 do begin
	j:=i;
	while true do begin
		l:=j shl 1;
		r:=l+1;
		if (l<=n) and (r<=n) then begin
			if (a[l]>=a[r]) and (a[j]<a[l]) then begin
				a[l]:=a[l] xor a[j];
				a[j]:=a[j] xor a[l];
				a[l]:=a[l] xor a[j];
				j:=l;
			end else 
			if (a[r]>=a[l]) and (a[j]<a[r]) then begin
				a[r]:=a[r] xor a[j];
				a[j]:=a[j] xor a[r];
				a[r]:=a[r] xor a[j];
				j:=r;
			end else break;
		end else begin
			if (l<=n) and (r>n) and (a[j]<a[l]) then begin
				a[l]:=a[l] xor a[j];
				a[j]:=a[j] xor a[l];
				a[l]:=a[l] xor a[j];
				j:=l;				
			end else break;
		end;	
	end;
end;
for i:=1 to n do
	write(a[i],' ');
writeln;
kk:=n-1;
for i:=1 to kk do begin
	b[i]:=ex_max;
	for j:=1 to kk-i+1 do
		write(a[j],' ');
	writeln;
end;
n:=kk+1;
b[n]:=a[1];
for i:=n downto 1 do
	write(b[i],' '); 
end.